<!-- 我要下单 -->
<template>
  <div style="padding: 16px;">
    <div style="display: flex;align-items: center;padding-left: 12px 0;">
      <el-input v-model="searchText" placeholder="请输入内容" style="max-width: 220px;margin-right: 16px;" />
      <el-button type="primary" icon="el-icon-search" @click="onSearch">搜索</el-button>
      <el-button type="primary" icon="el-icon-add" @click.native="openAdd = true">创建</el-button>
    </div>
    <CateTable :data="items" @editHandle="editHandle" @delHandle="delHandle"/>
    <!-- add -->
    <el-dialog
      title="添加分类"
      :visible.sync="openAdd"
      :before-close="handleClose">
      <AddCom @onClose="netGetList()"/>
      <!-- <span slot="footer" class="dialog-footer">
        <el-button @click="dialogVisible = false">取 消</el-button>
        <el-button type="primary" @click="dialogVisible = false">完 成</el-button>
      </span> -->
    </el-dialog>

    <!-- edit -->
    <el-dialog
      title="编辑分类"
      :visible.sync="openEdit"
      :before-close="handleClose">
      <EditCom @onClose="netGetList()" :row="currentData"/>
    </el-dialog>
  </div>
</template>

<script>
import CateTable from './cate_table.vue'
import AddCom from "./cate_add.vue"
import EditCom from "./cate_edit.vue"
import ServiceApi from "./api"
export default {
  components: {
    CateTable,
    AddCom,
    EditCom,
  },
  data() {
    return {
      activeName: 'first',
      name: '我要下单',
      openAdd:false,
      openEdit:false,
      items:[],
      currentData:{},
      searchText: ''
    }
  },
  mounted() {
    this.netGetList();
  },

  methods:{
    async netGetList() {
      this.openAdd = false;
      this.openEdit = false;
      var res = await ServiceApi.YzKindGetList({ queryBean: { searchText: this.searchText } });
      let body = res['data']
      let {data} = body;
      this.items = data;
    },

    editHandle({data}) {
      this.currentData = data;
      this.openEdit = true;
    },
    
    delHandle({data}) {
      this.$confirm('确认删除该条记录吗?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'success',
      }).then(action => {
        this.netDelKind(data.id);
      }).catch(() => {
        
      }); 
    },

    async netDelKind(id) {
      let {data} = await ServiceApi.YzKindDel(id);
      let {code,msg} = data;
        if (code == 200) {
          this.$message({
            message: msg,
            type: 'success'
          });
          this.netGetList();
        } else {
          this.$message.error(msg);
        }
    },
    onSearch() {
      this.netGetList();
    }
  },
}
</script>

<style>
.deleteBorder .el-tabs__nav-wrap::after{
    height: 0;
  }
</style>
